//
// Fifo.cpp for  in /home/lund/Projets/pizzaillo
// 
// Made by florian dewulf
// Login   <dewulf_f@epitech.net>
// 
// Started on  Mon Apr 15 16:31:47 2013 florian dewulf
// Last update Tue Apr 16 17:22:23 2013 florian dewulf
//

#include	"Fifo.hpp"

using namespace std;

Fifo::Fifo(const std::string &filename) : _str(""), _error(false), _file(filename)
{
  int	fifo;

  fifo = mkfifo(filename.c_str(), 0777);
  if (fifo == -1)
    this->_error = true;
}

Fifo::~Fifo()
{
  remove(this->_file.c_str());
}

bool	Fifo::getError() const
{
  return this->_error;
}

void	Fifo::setError(bool booleen)
{
  this->_error = booleen;
}

Fifo	&Fifo::operator<<(const string &str)
{
  cout << "Print : " << str << endl;
  this->_out << str << endl;
}

Fifo	&Fifo::operator>>(string &str)
{
  if (this->_in.good())
  {
    getline(this->_in, this->_str);
    str = this->_str;
    cout << ">>  " << this->_str << endl;
  }
}

void	Fifo::open_in()
{
  this->_in.open(this->_file.c_str());
  if (this->_in.is_open())
    cout << "Open" << endl;
  else
    cout << "Not Open" << endl;
}

void	Fifo::open_out()
{
  this->_out.open(this->_file.c_str());
  if (this->_out.is_open())
    cout << "Open" << endl;
  else
    cout << "Not Open" << endl;
}

void	Fifo::close_in()
{
  this->_in.close();
}

void	Fifo::close_out()
{
  this->_out.close();
}

string	Fifo::getStr() const
{
  return this->_str;
}
